package com.llly.controller;


import com.github.pagehelper.Page;
import com.llly.pojo.Easybuy_news;
import com.llly.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

@RestController
public class NewsController {



    @Autowired
    private NewsService newsService;

    //后台新闻页面

    public Page<Easybuy_news> showNews(@RequestParam Integer pageIndex){
        Page<Easybuy_news> newsPage = newsService.showNews(pageIndex);
        return newsPage;
    }


    @RequestMapping("/showNews")
    public Map<String,Object> ShowNews(@RequestParam Integer pageIndex){
        System.out.println("contro7777777777777777777********"+pageIndex);
        Page<Easybuy_news> page=showNews(pageIndex);
        Map map=new HashMap();
        map.put("pg",page.getResult());
        map.put("Total",page.getTotal());
        map.put("PageNum",page.getPageNum());
        map.put("Pages",page.getPages());
        System.out.println("contro2222222********"+page);
        return map;
    }
     //点击后进入详情页面
    @RequestMapping("/newsView")
    public Easybuy_news newsView(@RequestParam Integer id){
        System.out.println("************************进入9091详情方法");
        Easybuy_news newsView = newsService.newsView(id);
        return newsView;
    }

    //增
    @RequestMapping("/addnews")
    public int addnews(@RequestBody Easybuy_news en){
        int addNews = newsService.addNews(en);
        return addNews;

    }

    //删
    @RequestMapping("/delnews")
    public int delnews(@RequestBody @RequestParam Integer id){
        int delNews = newsService.delNews(id);
        return delNews;

    }

    //改
    @RequestMapping("/updatenews")
    public int updatenews(@RequestBody Easybuy_news en){
        int updatenews = newsService.updateNew(en);
        return updatenews;
    }

    //指定id查询
    @RequestMapping("/findById")
    public Easybuy_news findById(@RequestParam Integer id){
        Easybuy_news byid = newsService.findByid(id);
        return byid;
    }
}
